package com.lza.phone.mapper;

import com.lza.phone.entity.Capacity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 李钊澳
 * @since 2021-09-05
 */
public interface CapacityMapper extends BaseMapper<Capacity> {

    @Results({
            @Result(column = "userId",property = "userId"),
            @Result(column = "phoneId",property = "phoneId"),
            //property:在Capacity中的private User user; 返回值user
            @Result(column = "id",property = "user",one = @One(select = "com.lza.phone.mapper.UserMapper.selectById",fetchType= FetchType.EAGER)),
            @Result(column = "id",property = "phoneLists",many = @Many(select = "com.lza.phone.mapper.PhoneMapper.getOnePhone",fetchType= FetchType.EAGER))
    })
    //数据库里面的是phone 这边是从phone<list>里面查,里面没有capacity.*,user.*因此要加上c.*,u.*才能显示
    @Select("select p.*,c.*,u.* from phone p \n" +
            "LEFT JOIN capacity c \n" +
            "ON\n" +
            "p.id=c.phoneId\n" +
            "LEFT JOIN `user` u\n" +
            "ON\n" +
            "c.userId =u.id\n" +
            "where c.userId=#{userId}")
    public List<Capacity> showPkPhone(@Param("userId") Integer userId);

}
